<?php

/**
 * @access public
 */
class MySqlAdapter 
{
	public static $mysql_link;
	//public static $user_name="root";
	//public static $password="";
	//public static $database_address="localhost:8080";
	
	
	/**
	 * @access public
	 * return SingleTone of the mysql_link
	 */
	public static function get_mysql_link()
	 {
		 if (is_null(self::$mysql_link))
		 {
			 MySqlAdapter::connect();
		 }
		 return self::$mysql_link;
	 }
	 
	/**
	 * @access private
	 * Open connection to the mySql database.
	 * return $mysql_link
	 */
	public static function connect()
	{
		 
		self::$mysql_link = MySqlAdapter::connect1();		
		//Select Database
		//$result=mysql_select_db('ohel_shelomo',self::$mysql_link);
     	if (self::$mysql_link):
			$result = MySqlAdapter::connect2();
		else:
			die ("Could not connect to db " . mysql_error());
		endif;
	}
	
	public static function connect1()
	{
		return mysql_connect('localhost','root','');
	}
	
	/**
	*Access to the system data-base.
	*return pointer to the DB.
	*/
	public static function connect2()
	{
		return mysql_select_db('ohel_shelomo_2012');
	}
	
	
	//A wildcard query executor
	public static function query($qry)
	{
		$mysql_link = MySqlAdapter::get_mysql_link();
		$result = mysql_query($qry, $mysql_link);
		
		return $result;
	}
	
	//Fetch next row from a query result, or false if no more exists
	public static function nextResult($qry_result)
	{
		return mysql_fetch_array($qry_result);
	}
	
	//Close the connection to the mySql database, if exsits.
	public static function close()
	 {
		  if (!is_null(self::$mysql_link))
		  {
		   		mysql_close(self::$mysql_link);
				self::$mysql_link = NULL;
				
		  }
		    
	 }
	 
	
	 
}
?>